package com.pac.weixin.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.util.MsgKeyContent;
import com.pac.doctor.bean.DoctorBean;
import com.pac.doctor.service.DoctorService;
import com.pac.weixin.service.WeiXinService;

/**
 * 微信医生controller
 * 
 * @author lujun.chen
 * @version [版本号, 2015年3月2日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Controller
@Scope("prototype")
@RequestMapping("/weixin/doctor")
public class WxDoctorController {

	private static Logger logger = Logger.getLogger(WxDoctorController.class);

	@Autowired
	private DoctorService doctorService;

	@Autowired
	private WeiXinService weiXinService;

	/**
	 * 微信端查询医生信息
	 * 
	 * @param hostpitalId
	 *            医院ID
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/list")
	@ResponseBody
	public List<DoctorBean> queryDoctor(String hospitalId) {
		DoctorBean doctorBean = new DoctorBean();
		doctorBean.setHospitalId(hospitalId);
		return doctorService.queryDoctor(doctorBean);
	}

	/**
	 * 微信用户选择医生
	 * 
	 * @param userId
	 *            医生用户id
	 * @param nickname
	 *            医生昵称
	 * @param openid
	 *            微信用户openid
	 * @param hospitalId
	 *            医院ID
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/select")
	@ResponseBody
	public Map<String, Object> selDoctor(String userId, String nickname,
			String openid, String hospitalId) {

		boolean result = true;
		String msg = "操作成功";

		try {
			weiXinService.selDoctor(userId, nickname, openid, hospitalId);
		} catch (Exception ex) {
			result = false;
			msg = "操作失败";
			logger.error("微信端选择医生出错，" + ex);
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);

		return map;
	}

}
